package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.shopping.service.ICartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author wxgl
 * @date 2023-01-10 14:53
 * @describe
 */
@RestController
@RequestMapping("shopping")
public class WxglProductController {

    @Autowired
    ICartService iCartService;

    /**
     * @Author xiaowu
     * @Description // 删除购物车中的商品
     * @Date 15:18 2023/1/10
     * @Param [uid, pid]
     * @return {"success":true,"message":null,"code":200,"result":null,"timestamp":1673333974272}
     **/
    @DeleteMapping("carts/{uid}/{pid}")
    public ResponseData deleteCarts(@PathVariable("uid") String uid, @PathVariable("pid") String pid){
        iCartService.deleteCarts(uid,pid);
        return new ResponseUtil<>().setData(null);
    }

    /**
     * @Author xiaowu
     * @Description //  删除购物车中选中的商品
     * @Date 16:18 2023/1/10
     * @Param   http://124.221.21.69:8080/shopping/items/74
     * @return  {"success":true,"message":null,"code":200,"result":null,"timestamp":1673339476361}
     **/
    @DeleteMapping("items/{uid}")
    public ResponseData deleteCartsSelected(@PathVariable("uid") String uid){
        iCartService.deleteCartsSelected(uid);
        return new ResponseUtil<>().setData(null);
    }

    /**
     * @Author xiaowu
     * @Description //    全选/全不选购物车商品
     * @Date 17:14 2023/1/10
     * @Param   http://124.221.21.69:8080/shopping/items
     * @return   {"userId":"74","checked":true}
     **/
    @PutMapping("items")
    public ResponseData selectAllCartOrNot(@RequestBody Map map){

        iCartService.selectAllCartOrNot(map);
        return new ResponseUtil<>().setData(null);
    }
}
